<?php

namespace App\Models;

use Illuminate\Database\Eloquent\Factories\HasFactory;
use Illuminate\Database\Eloquent\Model;
use Illuminate\Database\Eloquent\SoftDeletes;
use Jedrzej\Pimpable\PimpableTrait;

class UserAddress extends Model
{
    use HasFactory;
    use PimpableTrait;
    use SoftDeletes;

    /**
     * 可执行搜索的字段
     */
    public $searchable = [
        'id',
        'city_id',
        'user_id',
        'is_default'
    ];

    /**
     * 可批量赋值字段
     */
    public $fillable = [
        'user_id',
        'consignee_name',
        'phone',
        'province',
        'city',
        'district',
        'detail',
        'post_code',
        'longitude',
        'latitude',
        'is_default',
    ];

    /**
     *进行排序的字段
     */
    public $sortable =[
        'is_default',
    ];


    /**
     * 默认使用倒叙的字段
     */
    public $defaultSortCriteria = [
        'id,desc',
    ];

    /**
     * 地址关联用户的id
     */
    public function user()
    {
       return $this->belongsTo(User::class,'user_id','id');
    }

    /**
     * 用户地址关联的城市的id
     */
    public function systemCities()
    {
        return $this->belongsTo(SystemCity::class,'city_id','id');
    }
}
